package com.ssx.controller;

import com.alibaba.fastjson.JSON;
import com.ssx.entity.Employees;
import com.ssx.entity.Pager;
import com.ssx.service.IEmployeesService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Package com.ssx.controller
 * @ClassName AdminController
 * @Copyright: Copyright (c) 2020
 * @Date 2020/10/26 8:30
 * @Company www.sudaoxi.com.cn
 * @Author 苏道羲
 * @Version 1.0
 * @Description
 */
@RestController
@RequestMapping("/admin")
@RequiresRoles("admin")
public class AdminController {
    @Autowired
    IEmployeesService employeesService;

    /**
     * 密码重置
     * @return
     */
    @RequestMapping("/resetPassword")
    public String resetPassword(int id){
        int i = employeesService.resetPassord(id);
        return i>0?"success":"failed";
    }


    @RequestMapping("/empList")
    @RequiresPermissions("admin:select")
    public String  empList(HttpServletRequest request){
        //数据库第几条
        int offset= Integer.parseInt(request.getParameter("offset"));
        //每页大小
        int limit= Integer.parseInt(request.getParameter("limit"));
        //当前页
        int current=(offset/limit)+1;
        Pager<Employees> pager = null;
        //查询条件
        String search = request.getParameter("search");
        //根据条件分页查询
        pager = new Pager<>(employeesService.selelctPageCount(search), employeesService.selelctPageByCondition(offset, limit, search));
        //返回json字符串

        return JSON.toJSONString(pager);
    }
}
